package com.frejoys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.frejoys.dao.entity.UserQrcode;
import com.frejoys.dao.mapper.UserQrcodeMapper;
import com.frejoys.service.UserQrcodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserQrcodeServiceImpl extends ServiceImpl<UserQrcodeMapper, UserQrcode> implements UserQrcodeService {

    @Override
    public UserQrcode getCodeInfo(Long userId) {
        LambdaQueryWrapper<UserQrcode> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(UserQrcode::getUserId, UserQrcode::getQrCode).eq(UserQrcode::getUserId, userId);
        return getOnly(wrapper);
    }

    @Override
    public boolean upQrCode(Long userId, String qrCode) {
        LambdaUpdateWrapper<UserQrcode> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(UserQrcode::getQrCode, qrCode);
        wrapper.eq(UserQrcode::getUserId, userId);
        return update(wrapper);
    }


}
